package coe.pumbaa

class User extends SecUser{
    static final String ACTIVE_USER = "active"
    static final String PENDING_USER = "pending"
    static final String BLOCK_USER = "block"
    
    String fname
    String lname
    String displayName
    byte[] avatar = null
    String studentID
    String signature
    String subscribe = "" //post_id
    String office
    String phoneNO
    String email
    String status
    String voter = "" //user_id
    String rejecter = ""
    String avatarType
    
    static belongsTo = [role:Role]
    
    static constraints = {
        email(blank:false, unique:true)
        password(blank:false, password:true)
        fname(blank:false)
        lname(blank:false)
        displayName(blank:false)
        avatar(nullable:true, maxSize: 1024 * 1024 * 2)
        studentID(blank:true,nullable:true)
        office(blank:true,nullable:true)
        phoneNO(blank:false)
        subscribe(nullable:true)
        voter(nullable:true)
        rejecter(nullable:true)
        signature(blank:true,nullable:true)
        avatarType(nullable:true)
    }
    
    def beforeInsert() {
	accountExpired = false
	accountLocked = false
	passwordExpired = false
        
        username = email
        encodePassword()
    }

    def beforeUpdate() {
        username = email
        if (isDirty('password')) {
            encodePassword()
        }
    }
}
